package com.favccxx.marketplace.order.infrastructure.config;

/*@Configuration
@EnableSwagger2
@Controller*/
public class Swagger2Config {

    /*@GetMapping(path = "/")
    public String swaggerHome() {
        return "redirect:swagger-ui.html";
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .build()
                .securitySchemes(securitySchemes())
                .securityContexts(securityContexts());
    }

    private List<ApiKey> securitySchemes() {
        List<ApiKey> apiKeys = new ArrayList<>();
        apiKeys.add(new ApiKey(AuthConstants.APP_KEY, AuthConstants.APP_KEY, "header"));
        apiKeys
                .add(new ApiKey(AuthConstants.AUTH_TOKEN_KEY, AuthConstants.AUTH_TOKEN_KEY, "header"));
        return apiKeys;
    }

    private List<SecurityContext> securityContexts() {
        List<SecurityContext> securityContexts = new ArrayList<>();
        securityContexts.add(SecurityContext.builder()
                .securityReferences(defaultAuth())
                .forPaths(PathSelectors.regex("^(?!auth).*$")).build());
        return securityContexts;
    }

    private List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope = new AuthorizationScope("global",
                "accessEverything");
        AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
        List<ApiKey> apiKeys = this.securitySchemes();
        List<SecurityReference> securityReferences = new ArrayList(apiKeys.size());
        Iterator var5 = apiKeys.iterator();
        while (var5.hasNext()) {
            ApiKey item = (ApiKey) var5.next();
            securityReferences.add(new SecurityReference(item.getName(), authorizationScopes));
        }
        return securityReferences;
    }*/
}
